/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.quantum.jbencoder.types;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author g073025
 */
public class BencodedList extends BencodedPrimitiveType {

    private final byte prefix = 'l';
    private List<BencodedType> values = null;

    public BencodedList() {
        values = new ArrayList<BencodedType>();
    }

    @Override
    protected void writePrefix(OutputStream os) throws IOException {
        os.write(prefix);
    }

    @Override
    protected void writeValue(OutputStream os) throws IOException {
        for(BencodedType value: values){
            value.serialize(os);
        }
    }

    @Override
    protected void writeSuffix(OutputStream os) throws IOException {
        os.write(suffix);
    }
    
    /**
     * add a new element into Bencoded List
     * @param element 
     */
    public void add(BencodedType element){
        this.values.add(element);
    }

    @Override
    public void deserialize(InputStream is) throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
